1. Field of the Present Invention
The present invention relates generally to computer graphics and more particularly to a circuit that efficiently determines fixed point frame buffer values from floating point values.
2. History of Related Art
Graphics display subsystems are almost universally employed in microprocessor based computer systems to facilitate a variety of graphics tasks and applications including computer-assisted drafting, architectural design, simulation trainers for aircraft and other vehicles, molecular modeling, virtual reality applications, and video games. Graphics processors, graphics adapters, and a variety of similarly designed computer products-provide specialized hardware to speed the execution of graphics instructions and rendering of graphic images. These processors and adapters typically include, for example,-circuitry optimized for translating, rotating, and scaling 3D graphic images.
In a typical application, a graphical image that is displayed on a display terminal or other output device is composed of one or more graphic primitives. For purposes of this disclosure, a graphic primitive may be thought of as one or more points, lines, or polygons that are associated with one another, such as by being connected to one another. Typically, the displayed image is generated by creating one or more graphic primitives, assigning various attributes to the graphic primitives, defining a viewing point and a viewing volume, determining which of the graphic primitives are within the defined viewing volume, and rendering those graphic primitives as they would appear from the viewing point. This process can require a tremendous amount of computing power to keep pace with the ever increasingly complex graphics applications that are commercially available. Accordingly, designers of graphics systems and graphics applications are continuously seeking cost effective means for improving the efficiency at which graphic images are rendered and displayed.
Typically a software application program generates a 3D graphics scene, and provides the scene, along with lighting attributes, to an application programming interface (API) such as the OpenGL(copyright) API developed by Silicon Graphics, Inc. Complete documentation of OpenGL(copyright) is available in M. Woo et al., OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 1.2 (Addison Wesley Longman, Inc. 1999) and D. Schreiner, OpenGL Reference Manual, Third Edition: The Official Reference Document to OpenGL, Version 1.2 (Addison Wesley Longman, Inc. 1999), both of which are incorporated by reference herein.
A 3D graphics scene typically includes of a number of polygons that are delimited by sets of vertices. The vertices are combined to form larger primitives, such as triangles or other polygons. The triangles (or polygons) are combined to form surfaces, and the surfaces are combined to form objects. Each vertex is associated with a set of attributes. Vertex attributes may include a position, including three Cartesian coordinates x, y, and z, a material color, which describes the color of the object to which the vertex belongs, and a normal vector, which describes the direction to which the surface is facing at the vertex. Each vertex may also be associated with texture coordinates and/or an alpha (transparency) value. In addition, the scene itself may be associated with a set of attributes including, as examples, an ambient color that typically describes the amount of ambient light and one or more individual light sources. Each light source has a number of properties associated with it, including a direction, an ambient color, a diffuse color, and a specular color.
Rendering is employed within the graphics system to create two-dimensional image projections of a 3D graphics scene for display on a monitor or other display device. Typically, rendering includes processing geometric primitives (e.g., points, lines, and polygons) by performing one or more of the following operations as needed: transformation, clipping, culling, lighting, fog calculation, and texture coordinate generation. Rendering further includes processing the primitives to determine component pixel values for the display device, a process often referred to specifically as rasterization.
The OpenGL(copyright) API specification and other API""s such as the graPHIGS API define the allowed vertex and scene attributes and the equations used to determine attribute values. During rasterization, the primitives of a scene (including all of its attributes), are used to determine values (red, green blue, alpha, and stencil) corresponding to each pixel of a display screen. These values are stored in a storage element referred to as the frame buffer. Thus, the frame buffer contains a digital representation of an image that is to be displayed on a display screen.
Floating point computations are usually required to calculate the values to be loaded into the frame buffer. Typically, however, the frame buffer is structured as a set of fixed point data points corresponding to each pixel of the display screen. It is, therefore, usually necessary to convert floating point numbers to fixed point values suitable for storage in the frame buffer. In an 8-bit frame buffer, for example, the xe2x80x9credxe2x80x9d frame buffer value for each pixel can assume a value in the range of 0 to 255.
In a conventional rasterization process, the conversion of a floating point number to a fixed point number suitable for storage in an 8-bit register would be performed in software by multiplying the input value by 255, adding a suitable rounding offset such as 0.5 to the value, and truncating the fractional component of the result. The truncated value is then compared to the maximum permiitted value (i.e., 255) and a minimum permitted value. The appropriate limit value is substituted for the value if an overflow or underflow occurs. Finally, the resulting floating point value is converted to a fixed point number. Those familiar with the performance of floating point operations will appreciate that the floating point to fixed point conversion process described could become a performance bottleneck in a demanding graphics application. It would therefore be desirable to implement a circuit capable of producing frame buffer fixed point values from floating point values in less time than required to perform the conversion in software.
The problems identified above are addressed by a floating point to fixed point converter as disclosed herein that is suitable for determining values for an n-bit frame buffer of a graphics adapter. The converter includes a floating point unit that receives a floating point input value and calculates a floating point adjusted input value from the received value. Comparator circuitry is configured to compare a fixed point portion of the adjusted input value to a fixed point comparison value and to generate a fixed point output value responsive to the result of the comparison. The floating point unit may add a floating point constant to the received input to calculate the adjusted input value. The floating point constant may include a rounding component and a range component. The range component adjusts received values into a range defined by a single floating point exponent value such as the floating point range from 1.0 to 2.0 (which is defined by the exponent value 127 in IEEE floating point format). In one embodiment, the rounding component shifts received values that are within a range of x/(2nxe2x88x921)xc2x11/(2*(2nxe2x88x921)) (which is the floating point range corresponding to a frame buffer value of x) into a range bounded by x/(2nxe2x88x921) and (x+1)/(2nxe2x88x921) to take advantage of special properties of the adjusted range""s boundary values to simplify the comparator circuitry. The comparator circuitry may include a comparator configured to compare the exponent field of the adjusted input value to 0x7F and a comparator that compares the value of a first portion of the adjusted input value mantissa to a second portion of the mantissa. The converter may produce a frame buffer value of 0x00 if the exponent field is less than 0x7F and a frame buffer value of 0xFF if the exponent field is greater than 0x7F. The converter may generate a frame buffer equal to the value of the first portion of the adjusted input value mantissa if the first portion is greater than the second portion and a frame buffer equal to the value of the first portion decremented by one if the first portion is less than the second portion.